package com.amt.iptvsetting.business.flutter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.util.Log;

import com.alibaba.android.arouter.facade.annotation.Route;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

@Route(path = "/zhouwd/flutter_activity")
public class ZFlutterActivity extends FlutterActivity implements MethodChannel.MethodCallHandler , EventChannel.StreamHandler {

    private static final String CHANNEL = "samples.flutter.io/battery";
    public static String EVENT_CHANNEL = "samples.flutter.io/battery";
    private static final String ANDROID_DATA = "AndroidData";

    private static final String TAG = ZFlutterActivity.class.getSimpleName();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //View view = Flutter.createView(this, getLifecycle(), "/");
        //setContentView(view);

        GeneratedPluginRegistrant.registerWith(this);

        //1.通道名
        MethodChannel channel = new MethodChannel(getFlutterView(), CHANNEL);
        channel.setMethodCallHandler(this);

        EventChannel eventChannel = new EventChannel(getFlutterView(), EVENT_CHANNEL);
        eventChannel.setStreamHandler(this);
    }

    @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        if (methodCall == null) {
            return;
        }

        switch (methodCall.method) {
            case ANDROID_DATA:
                Log.i(TAG, "onMethodCall: ANDROID_DATA");
                result.success("hahahahahha");
                break;

        }

    }

    @Override
    public void onListen(Object o, EventChannel.EventSink eventSink) {
        Log.i(TAG, "onListen: ");
        eventSink.success("hehehehehehehehehe");
    }

    @Override
    public void onCancel(Object o) {

    }
}
